package icu.sehnen.servlet;

import com.alibaba.fastjson.JSONObject;
import icu.sehnen.dao.UserDao;
import icu.sehnen.model.UserModel;
import icu.sehnen.service.UserService;
import icu.sehnen.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/register")
public class registerUserServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserModel userModel=new UserModel();
        System.out.println(req.getParameter("username"));
        userModel.setUsername(req.getParameter("username"));
        userModel.setPassword(req.getParameter("password"));
        userModel.setSex(req.getParameter("sex"));
        userModel.setPhone(req.getParameter("phone"));
        userModel.setEmail(req.getParameter("email"));
        userModel.setBirthday(req.getParameter("birthday"));
        userModel.setHobby(req.getParameter("hobby"));
        UserService userService=new UserServiceImpl();
        String result=userService.register(userModel);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("result",result);
        resp.getWriter().println(jsonObject);
    }
}
